import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import programinzynierka.DodajJDialog;
import programinzynierka.WynikiJDialog;
import java.io.*;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ProgramInzynierka extends javax.swing.JFrame 
{    
    private DodajJDialog addWarunek;
    private WynikiJDialog wyniki;
    HashMap<Integer, Double> map = new HashMap<>();
    String nazwaPliku;
    Zegar zegarKlient = new Zegar(1);
        
    public ProgramInzynierka() 
    {
        GregorianCalendar data = new GregorianCalendar();
        nazwaPliku = "Klient_log_"+data.get(Calendar.YEAR)+"_"+data.get(Calendar.MONTH)+"_"+data.get(Calendar.DAY_OF_MONTH)+"_"+data.get(Calendar.HOUR)+"_"+data.get(Calendar.MINUTE)+"_"+data.get(Calendar.SECOND)+".txt";        
        
        initComponents();
        buttonGroup1.add(jRadioButton1);
        buttonGroup1.add(jRadioButton2);
        buttonGroup1.add(jRadioButton3);
        buttonGroup1.add(jRadioButton4);
        
        jRadioButton2.addItemListener(new ItemListener() 
        {
            public void itemStateChanged(ItemEvent evt) 
            {
                if (evt.getStateChange()==ItemEvent.SELECTED) 
                    jTextField5.setEnabled(true);
                if (evt.getStateChange()==ItemEvent.DESELECTED) 
                    jTextField5.setEnabled(false);
            }
        });

        jRadioButton4.addItemListener(new ItemListener() 
        {
            public void itemStateChanged(ItemEvent evt) 
            {
                if (evt.getStateChange()==ItemEvent.SELECTED) 
                    jTextField6.setEnabled(true);
                if (evt.getStateChange()==ItemEvent.DESELECTED) 
                    jTextField6.setEnabled(false);
            }
        });  
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel8 = new javax.swing.JLabel();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jButton5 = new javax.swing.JButton();
        jTextField7 = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();

        jLabel8.setText("jLabel8");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Klient");
        setAlwaysOnTop(true);
        setAutoRequestFocus(false);
        setBounds(new java.awt.Rectangle(100, 30, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Współrzędne"));

        jTextField2.setNextFocusableComponent(jTextField3);

        jTextField1.setNextFocusableComponent(jTextField2);

        jLabel1.setText("x");

        jLabel2.setText("y");

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/programinzynierka/wsp.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel11)
                        .addGap(284, 284, 284))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel11))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Ilość elementów"));

        jLabel3.setText("nx");

        jTextField3.setNextFocusableComponent(jTextField4);

        jTextField4.setNextFocusableComponent(jButton1);

        jLabel4.setText("ny");

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/programinzynierka/wez.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel9))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel9))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Warunki brzegowe"));

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Węzeł", "Wartość"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Double.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTable1.setRequestFocusEnabled(false);
        jTable1.setRowHeight(18);
        jTable1.setRowSorter(null);
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTable1.getTableHeader().setResizingAllowed(false);
        jTable1.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getAccessibleContext().setAccessibleName("");
        jTable1.getAccessibleContext().setAccessibleDescription("");

        jButton3.setText("Wyczyść");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton2.setText("Usuń");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setText("Dodaj");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Obliczenia"));

        jTextField5.setEnabled(false);

        jTextField6.setEnabled(false);
        jTextField6.setNextFocusableComponent(jButton6);

        jLabel5.setText("| warunek końca iteracji");

        jLabel6.setText("| warunek końca iteracji");

        jRadioButton1.setText("Metoda Gaussa");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jRadioButton2.setText("Metoda Gaussa-Seidela");

        jRadioButton3.setText("Metoda Gaussa-Jordan");

        jRadioButton4.setText("Metoda kwadratu gradientów sprzężonych");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton2)
                            .addComponent(jRadioButton4))
                        .addGap(35, 35, 35)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRadioButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRadioButton4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton5.setText("Zakończ");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jTextField7.setText("127.0.0.1");

        jButton6.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jButton6.setText("Oblicz");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel12.setText("IP:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField7)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        
        GregorianCalendar data = new GregorianCalendar();
        double d = 0,b = 0;
        int nd = 0,nb = 0;
        double zakres1 = 1;
        double zakres2 = 1;   
        boolean czyok = true;
        Dane1 dane = new Dane1();
        Dane2 daneWyniki = new Dane2();
        String ip = null;
        
        try {
            d=(Integer.valueOf(jTextField1.getText()));     //x
        } catch (NumberFormatException nfe) 
        {
            JOptionPane.showMessageDialog(rootPane, "Podaj wartości x", "", 2);
            czyok=false;
        }
        try {
            ip=jTextField7.getText();     //x
        } catch (NumberFormatException nfe) 
        {
            JOptionPane.showMessageDialog(rootPane, "Podaj ip", "", 2);
            czyok=false;
        }
        try {
            b=(Integer.valueOf(jTextField2.getText()));     //y
        } catch (NumberFormatException nfe) 
        {
            JOptionPane.showMessageDialog(rootPane, "Podaj wartości y", "", 2);
            czyok=false;
        }
        try {
            nd=(Integer.valueOf(jTextField3.getText()));    //ilość wezlow po x
        } catch (NumberFormatException nfe) 
        {
            JOptionPane.showMessageDialog(rootPane, "Podaj wartości nd", "", 2);
            czyok=false;
        }
        try {
            nb=(Integer.valueOf(jTextField4.getText()));    //ilość wezlow po y
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(rootPane, "Podaj wartości nb", "", 2);
            czyok=false;
        }
        if(jRadioButton2.isSelected())
            try {
                zakres1=(Double.valueOf(jTextField5.getText()));     //x
            } catch (NumberFormatException nfe) 
            {
                JOptionPane.showMessageDialog(rootPane, "Podaj warunek końca iteracji 1", "", 2);
                czyok=false;
            }
        if(jRadioButton4.isSelected())
            try {
                zakres2=(Double.valueOf(jTextField6.getText()));     //x
            } catch (NumberFormatException nfe) 
            {
                JOptionPane.showMessageDialog(rootPane, "Podaj warunek końca iteracji 2", "", 2);
                czyok=false;
            }
        
        if(d<1) {czyok=false; JOptionPane.showMessageDialog(this,"x>0","", JOptionPane.WARNING_MESSAGE);}
        if(b<1) {czyok=false; JOptionPane.showMessageDialog(this,"y>0","", JOptionPane.WARNING_MESSAGE);}
        if(nd<2) {czyok=false; JOptionPane.showMessageDialog(this,"nx>1","", JOptionPane.WARNING_MESSAGE);}
        if(nb<2) {czyok=false; JOptionPane.showMessageDialog(this,"ny>1","", JOptionPane.WARNING_MESSAGE);}
        if(jRadioButton2.isSelected()) if(zakres1<=0) {czyok=false; JOptionPane.showMessageDialog(this,"warunek końca iteracji 1>0","", JOptionPane.WARNING_MESSAGE);}
        if(jRadioButton4.isSelected()) if(zakres2<=0) {czyok=false; JOptionPane.showMessageDialog(this,"warunek końca iteracji 2>0","", JOptionPane.WARNING_MESSAGE);}
        
        if(czyok == true)
        {
                dane.b=b;
                dane.d=d;
                dane.nb=nb;
                dane.nd=nd;
                dane.zakres=0.0;
                if(jRadioButton1.isSelected()) dane.rb=1;
                if(jRadioButton2.isSelected()) dane.rb=2;
                if(jRadioButton3.isSelected()) dane.rb=3;
                if(jRadioButton4.isSelected()) dane.rb=4;
                if(jRadioButton2.isSelected()) dane.zakres=zakres1;
                if(jRadioButton4.isSelected()) dane.zakres=zakres2;
                dane.map = map;
                dane.zegar = zegarKlient.getLocalMax();
                
            try {                
                Socket socket = null; // gniazdko
                ObjectInputStream ois = null;
                ObjectOutputStream oos = null;
                try {
                    socket = new Socket(ip, 4444);
                    System.out.println("Czekam na wiadomosc z Servera...");
                    oos = new ObjectOutputStream(socket.getOutputStream());
                    ois = new ObjectInputStream(socket.getInputStream());
                }
                catch (UnknownHostException e) 
                {
                    System.err.println("Nieznany adres hosta");
                    JOptionPane.showMessageDialog(rootPane, "Nieznany adres hosta", "", 2);
                    czyok=false;                    
                }
                catch (IOException e) 
                {
                    System.err.println("Blad operacji Wejscia/Wyjscia - I/O error");
                    JOptionPane.showMessageDialog(rootPane, "Nie znaleziono serwera", "", 2);
                    czyok=false;
                }
                catch(Exception e) {
                    System.err.println("Błąd nawiązywania połączenia");
                    JOptionPane.showMessageDialog(rootPane, "Błąd nawiązywania połączenia", "", 2);
                    czyok=false;                    
                }        

                if(czyok==true)
                {
                    oos.writeObject(dane);
                    oos.flush();
                    PrintWriter zapis = null;
                    zegarKlient.increment();
                    try 
                    {
                        zapis = new PrintWriter(new FileWriter(nazwaPliku, true));
                    } catch (FileNotFoundException ex) 
                    {
                        Logger.getLogger(ProgramInzynierka.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    data=new GregorianCalendar();
                    zapis.println("Data i czas: "+data.get(Calendar.DAY_OF_MONTH)+"."+data.get(Calendar.MONTH)+"."+data.get(Calendar.YEAR)+" godz: "+data.get(Calendar.HOUR)+":"+data.get(Calendar.MINUTE)+":"+data.get(Calendar.SECOND));            
                    zapis.println("Zegar: " + zegarKlient.getLocalMax());
                    zapis.println("Wysyłam dane");            
                    zapis.close();
                        try {
                            daneWyniki = (Dane2) ois.readObject();
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(ProgramInzynierka.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    zegarKlient.increment();
                    try 
                    {
                        zapis = new PrintWriter(new FileWriter(nazwaPliku, true));
                    } catch (FileNotFoundException ex) 
                    {
                        Logger.getLogger(ProgramInzynierka.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    zapis.println("Zegar: " + zegarKlient.getLocalMax());
                    zapis.println("Otrzymałem dane");            
                    zapis.println();     
                    zegarKlient.setClock(0, daneWyniki.zegar);
                    zapis.println("Zegar: " + zegarKlient.toString());
                    zapis.println();
                    zapis.close();

                    
                    System.out.println("Server: czas: " + daneWyniki.czaswykonania + " WYNIKI: \n" + daneWyniki.wyniki);
                
                    oos.close();
                    ois.close();        
                    socket.close();
                }
            } catch (IOException ex) {
                Logger.getLogger(ProgramInzynierka.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        System.gc();
        
        if(czyok==true)
        {
            if (wyniki == null) 
                wyniki = new WynikiJDialog(this, true);
            wyniki.cleanWyniki();
            wyniki.setArea(daneWyniki.wyniki, daneWyniki.czaswykonania);
            wyniki.setVisible(true);  
            PrintWriter zapis = null;
            try {
                zapis = new PrintWriter(data.get(Calendar.YEAR)+"_"+data.get(Calendar.MONTH)+"_"+data.get(Calendar.DAY_OF_MONTH)+"_"+data.get(Calendar.HOUR)+"_"+data.get(Calendar.MINUTE)+"_"+data.get(Calendar.SECOND)+".txt");
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ProgramInzynierka.class.getName()).log(Level.SEVERE, null, ex);
            }            
            
            for(int i=0; i<daneWyniki.wyniki.length();i++)
            {
                zapis.print(daneWyniki.wyniki.charAt(i)); 
                if( daneWyniki.wyniki.charAt(i) == '\n')
                    zapis.println();
            }
            zapis.close(); 
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (addWarunek == null) {
            addWarunek = new DodajJDialog(this, true);
        }
        addWarunek.setVisible(true);
        
        if (addWarunek.isOK1()) 
        {
            if(addWarunek.getWezel()<1) 
                JOptionPane.showMessageDialog(this,"Węzeł>0","", JOptionPane.WARNING_MESSAGE);
            else
                map.put(addWarunek.getWezel(), addWarunek.getWartosc1());        
        }
        if (addWarunek.isOK2()) 
        {
            
        double d,b;
        int nd,nb,nw,ne;
	double dx;			//krok po x
	double dy;			//krok po y
	int ka;				//pomocnicza
	double x[];			//wartości x
	double y[];			//wartości y   
        boolean czydodano=false;
        d=0;
        b=0;
        nd=0;
        nb=0;
        try {
            d=(Integer.valueOf(jTextField1.getText()));     //x
        } catch (NumberFormatException nfe) 
        {
            JOptionPane.showMessageDialog(rootPane, "Podaj wartości x", "", 2);
        }
        try {
            b=(Integer.valueOf(jTextField2.getText()));     //y
        } catch (NumberFormatException nfe) 
        {
            JOptionPane.showMessageDialog(rootPane, "Podaj wartości y", "", 2);
        }
        try {
            nd=(Integer.valueOf(jTextField3.getText()));    //ilość wezlow po x
        } catch (NumberFormatException nfe) 
        {
            JOptionPane.showMessageDialog(rootPane, "Podaj wartości nd", "", 2);
        }
        try {
            nb=(Integer.valueOf(jTextField4.getText()));    //ilość wezlow po y
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(rootPane, "Podaj wartości nb", "", 2);
        }
        
        if(d<1) JOptionPane.showMessageDialog(this,"x>0","", JOptionPane.WARNING_MESSAGE);
        if(b<1) JOptionPane.showMessageDialog(this,"y>0","", JOptionPane.WARNING_MESSAGE);
        if(nd<2) JOptionPane.showMessageDialog(this,"nx>1","", JOptionPane.WARNING_MESSAGE);
        if(nb<2) JOptionPane.showMessageDialog(this,"ny>1","", JOptionPane.WARNING_MESSAGE);
        
        nw=nb*nd;               //ilość węzłów
	ne=2*(nb-1)*(nd-1);	//ilość elementów
        
        x = new double [nw+1];
        y = new double [nw+1];
        
        dx= (d/(nd-1));	//krok po x
        dy= (b/(nb-1));	//krok po y

        for (int i=1;i<=nd;i++)
	{
            for (int j=1;j<=nb;j++)
            {
                ka=(i-1)*nb+j;
                x[ka]=(i-1)*dx;
                if(i==nd) x[ka]=d;
                y[ka]=(j-1)*dy;
                
            }		        	
	}
        
        for(int i=1; i<=nw; i++)
        {
            if(x[i]==addWarunek.getWezelX())     
            {
                map.put(i, addWarunek.getWartosc2());   
                czydodano=true;
            }
        }
        if(czydodano==false) JOptionPane.showMessageDialog(this,"Podaj prawidłową wartość x","", JOptionPane.WARNING_MESSAGE);
        
        }        
        addWarunek.cleanaddWarunek();
               
        Vector<String> tableHeaders = new Vector<>();
        Vector tableData = new Vector();
        tableHeaders.add("Węzeł");
        tableHeaders.add("Wartość");
        Set<Integer> kluczmap = map.keySet();
          for(Integer k : kluczmap){
            Vector<Object> oneRow = new Vector<>();
            oneRow.add(k);
            oneRow.add(map.get(k));
            tableData.add(oneRow);
          }
        jTable1.setModel(new DefaultTableModel(tableData, tableHeaders));
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        map.remove((Integer) jTable1.getValueAt(jTable1.getSelectionModel().getLeadSelectionIndex(), 0));
        Vector<String> tableHeaders = new Vector<>();
        Vector tableData = new Vector();
        tableHeaders.add("Węzeł");
        tableHeaders.add("Wartość");
        Set<Integer> kluczmap = map.keySet();
          for(Integer k : kluczmap){
            Vector<Object> oneRow = new Vector<>();
            oneRow.add(k);
            oneRow.add(map.get(k));
            tableData.add(oneRow);
          }
        jTable1.setModel(new DefaultTableModel(tableData, tableHeaders));
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        map.clear();
        Vector<String> tableHeaders = new Vector<>();
        Vector tableData = new Vector();
        tableHeaders.add("Węzeł");
        tableHeaders.add("Wartość");
        Set<Integer> kluczmap = map.keySet();
          for(Integer k : kluczmap){
            Vector<Object> oneRow = new Vector<>();
            oneRow.add(k);
            oneRow.add(map.get(k));
            tableData.add(oneRow);
          }
        jTable1.setModel(new DefaultTableModel(tableData, tableHeaders));      
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ProgramInzynierka.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ProgramInzynierka().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    // End of variables declaration//GEN-END:variables
}